const windowWidth = getApp().globalData.windowWidth;
const app = getApp()
Page({
  data: {
    active: 'recommend',
    applyHeight: 0,
    resizeImg: '?x-image-process=image/resize,m_lfit,w_' + windowWidth,
    applyImgs: [
      '/miniprogram/certificate/1.png',
      '/miniprogram/certificate/2.png',
      '/miniprogram/certificate/3.png',
      '/miniprogram/certificate/4.png',
      '/miniprogram/certificate/5.png',
      '/miniprogram/certificate/6.png',
      '/miniprogram/certificate/7.png',
      '/miniprogram/certificate/8.png',
      '/miniprogram/certificate/9.png',
      '/miniprogram/certificate/10.png',
      '/miniprogram/certificate/11.png'
    ],
    token: '',
    scrollHeight: 0
  },
  options: {
    styleIsolation: 'shared'
  },
  onLoad(options) {
    if (options.active ) {
      this.setData({
        active: active
      })
    }
  },
  onShow() {
    this.setData({
      token: app.globalData.token || wx.getStorageSync('token')
    })
    const windowHeight = wx.getSystemInfoSync().windowHeight
    let query = wx.createSelectorQuery().in(this);
    query.select('.custom-home-nav').boundingClientRect();
    query.exec((res) => {
      this.setData({
        scrollHeight: windowHeight - res[0].height - 42 - 44
      })
      getApp().globalData.navHeight = res[0].height
    });
  },
  toPageMessage() {
    wx.navigateTo({ url: '/packageA/pages/message/message' })
  },
  onChange(e) {
    this.setData({
      active: e.detail.name
    })
    const recommendComponent = this.selectComponent('#recommend').selectComponent('#moduleWrap').selectComponent('.mo-custom-dropdown-item')
    const findTeahcerComponent = this.selectComponent('#findTeacher').selectComponent('#findModule').selectComponent('.mo-custom-dropdown-item')
    recommendComponent.toggle(false)
    findTeahcerComponent.toggle(false)
  },
  toCert() {
    if (!this.data.token) {
      wx.showModal({
        title: '提示',
        content: '请先登录',
        success (res) {
          if (res.confirm) {
            app.bindLogin().then(res => {
              this.setData({
                token: app.globalData.token || wx.getStorageSync('token')
              })
            })
          }
        }
      })
    } else {
      wx.navigateTo({
        url: '/packageA/pages/textualResearch/textualResearch'
      })
    }
  },
  toSearch() {
    wx.navigateTo({
      url: '/pages/search/search'
    })
  }
})
